package offer;

class offer53 {
}
class Solution53 {
    public static int search(int[] nums, int target) {
        int start = 0;
        int mid;
        int end=nums.length-1;
        int res = 0 ;
        boolean flag = false;
        while (start<end)
        {
            mid = (start+end)/2;
            if(nums[mid]==target)
            {  flag =true;
                break;
            }
            if(nums[mid]<target)
            {
                start = mid+1;

            }else {
                end = mid-1;
            }
        }
        if(flag==true)
        {
           for(int i = start;i<=end;i++)
           {
               if(target==nums[i])
               {
                   res++;
               }
           }
        }else
        {
            res = 0;
        }
    return res;
    }
//[5,7,7,8,8,10]
//        8
    public static void main(String[] args) {
        int [] nums = {5,7,7,8,8,10};
        search(nums,8);
    }
}